package cn.com.pc.content.dto;

import cn.com.pc.content.domain.tag.TagRelation;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

/**
 * 标签关系
 */
@NoArgsConstructor
@Data
@ToString
public class TagRelationDTO {
    @NotNull(message = "leftId不能为空")
    private Long leftId;
    private String leftName;

    @NotNull(message = "rightId不能为空")
    private Long rightId;
    private String rightName;

    private String tagName;

    private Boolean onShelve;

    @NotNull(message = "relation不能为空")
    private String relation;

    private LocalDateTime createdAt;

    public static TagRelationDTO from(TagRelation tagRelation) {
        TagRelationDTO tagRelationDTO = new TagRelationDTO();
        BeanUtils.copyProperties(tagRelation, tagRelationDTO);
        tagRelationDTO.setLeftId(tagRelation.getRelationKey().getLeft().getId());
        tagRelationDTO.setRightId(tagRelation.getRelationKey().getRight().getId());
        return tagRelationDTO;
    }
}
